package gui; /**
 * Created with IntelliJ IDEA.
 * Description:
 * User: YKH
 * Date: 2022-12-08
 * Time: 20:24
 */

import javax.swing.*;
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.TextEvent;
import java.awt.event.TextListener;

public class MouseKey2 extends JFrame implements ActionListener {
    private JTextArea jTextArea;
    TextField textField;

    public MouseKey2() {
        textField = new TextField();
        setLayout(null);
        textField.setBounds(0, 0, 300, 20);
        textField.addActionListener(this);
        textField.addTextListener(new TextListener() {
            @Override
            public void textValueChanged(TextEvent e) {
                jTextArea.setText(textField.getText());
            }
        });
        jTextArea = new JTextArea();
        jTextArea.setBounds(0, 20, 300, 270);
        jTextArea.setFont(new Font("宋体", Font.BOLD, 20));
        setSize(300, 300);
        this.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
        add(textField);
        add(jTextArea);
        setVisible(true);
    }


    public static void main(String[] args) {
        new MouseKey2();
    }

    @Override
    public void actionPerformed(ActionEvent e) {
        jTextArea.setText("");
    }
}
